// pages/custom/custom.js
const http=require("../../utils/http");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    Steps: 0,
    StepsList: ["旅游周期", "旅行偏好", "洲", "国家", "城市", "预算", "填写信息"],
    curday: 4,
    countryList:[],
    selectedCountry:[],
    cityMap:{},
    poi_list:[],
cateList:[
  {id:1,name:'风光休闲',state:false},
  {id:2,name:'蜜月旅行',state:false},
  {id:3,name:'光影拍摄',state:false},
  {id:4,name:'购物享受',state:false},
  {id:5,name:'亲子度假',state:false},
  {id:6,name:'美食盛宴',state:false},
  {id:7,name:'游学充电',state:false},
  {id:8,name:'人文历史',state:false},
  {id:9,name:'旅拍婚纱',state:false},
  {id:10,name:'酒店体验',state:false},
],
continentList:[
  {name:'欧洲',name_en:'Europe',continent_en:'Europe'},
  {name:'亚洲',name_en:'Asia',continent_en:'Asia'},
  {name:'北美洲',name_en:'N America',continent_en:'NorthAmerica'},
  {name:'大洋洲',name_en:'Oceania',continent_en:'Oceania'},
  {name:'非洲',name_en:'A frica',continent_en:'Africa'},
  {name:'南美洲',name_en:'S America',continent_en:'SouthAmerica'},
],
    progress: 83.4,
    percent: 16.6,
  },
  customData:{
    continent_en:"",
    country_en:[]
  },
  slider4change(ev) {
    this.setData({
      curday: ev.detail.value
    })
  },
  nextStep(ev) {
  if(ev.currentTarget.dataset.name){
    console.log(this.customData);
    this.customData.continent_en=ev.currentTarget.dataset.en;
    console.log(this.customData.continent_en);
    http.request(`/requirement/destination/countries2/${ev.currentTarget.dataset.name}`,'','get').then(res=>{
      this.setData({
        countryList:res.data.map(item=>{
          item.state=false;
          return item;
        })
      })
    })
  }

    if(this.data.Steps==1&&this.data.cateList.every(i=>!i.state)){
      wx.showToast({
        title: '请你选择旅行偏好',
        icon:'none'
      })
    }
    else if(this.data.Steps==3&&this.data.countryList.every(i=>!i.state)){
      wx.showToast({
        title: '请你选择国家',
        icon:'none'
      })
    }
    else if(this.data.Steps==3){
      let list=this.data.countryList.map(item=>{
        if(item.state){
          return item.countryEn
        }
      }).filter(i=>typeof i !== 'undefined');
      this.customData.country_en=list;
      console.log(this.customData.country_en);
      http.request("/requirement/destination/getCitiesByCountries",{"continent_en":[this.customData.continent_en],"country_en":this.customData.country_en,"order_by":"SHOW_TOP","show_flag":1,"type":2},'post').then(res=>{
        console.log(res);
        console.log(res.data.countryList);
        this.setData({
          selectedCountry:res.data.countryList,
          cityMap:res.data.cityMap,
          poi_list:res.data.poi_list,
          Steps:this.data.Steps+1
        })
      })
      console.log(this.data.selectedCountry);
    }
    else{
    this.setData({
      Steps: this.data.Steps + 1
    })}
  },
  selectCate(ev){
    const index=ev.currentTarget.dataset.index;
    const list=[...this.data.cateList];
    list[index].state=!list[index].state;
    this.setData({
      cateList:list
    })
  },
  selectCountry(ev){
    let list=[...this.data.countryList];
    const index=ev.currentTarget.dataset.index;
    list[index].state=!list[index].state;
    this.setData({
      countryList:list
    })
  },
  prevStep(){
    this.setData({
      Steps: this.data.Steps - 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})